
%compute TMI EU bounds for random data (THIS WILL TAKE LONG!!)
clear
T = readtable('choices_and_prices_random_B.csv');

ID = table2array(T(:,1));
dataset = T(:,2:end);

e_lb = zeros(size(dataset,1),1);
e_ub = ones(size(dataset,1),1);
epsilons = .5*ones(size(dataset,1),1);

tic
for n = 1:14
	evalc('boole = system_has_solution(dataset,epsilons,50,25,true)');

	e_lb(boole==0) = epsilons(boole==0); % didn't find solution for given epsilon --> expected utility TMI is at least that epsilon
	e_ub(boole==1) = epsilons(boole==1); % found solution for given epsilon --> expected utility TMI is at most that epsilon

    epsilons(ismember(boole,[0,-1])) = epsilons(ismember(boole,[0,-1])) + 2^(-(n+1)); % note: increase also if not clear whether a solution exists (boole==-1)
	epsilons(boole==1) = epsilons(boole==1) - 2^(-(n+1));
    
    sprintf('iteration number %d',n)
    tabulate(epsilons)
    toc
end
writetable(array2table([ID e_lb e_ub]), 'epsilons_random_B.csv');
